<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>组件通信</title>
</head>

<body>
  <div id="app">
    <child></child>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
  <script>
    Vue.component('child', {
      template: '<p>{{msg}}</p>',
      data() {
        return {
          foo: '佛哦哦哦哦哦',
          msg: ''
        }
      },
      created() {
        this.msg = this.$root.foo
      }
    })
    const app = new Vue({
      el: "#app",
      data: {
        foo: 'foo'
      },
    })
  </script>
</body>

</html>